import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))

const typeData = [{name:'收样时间-接收标本箱时间',value:'st_type_1'},{name:'接收标本箱时间-批准报告时间',value:'st_type_2'},{name:'收样时间-批准报告时间',value:'st_type_3'}]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '接收时间',		names: ['start_at','end_at'], 	type:'date-range' },
			{ label: '统计类型',		name: 'st_type',				type: 'select', data:typeData, value:'st_type_1', isClear:false },
			{ label: '科室',		name: 'project_parent_id',		type: 'select', loading:true, idStr:'uuid',nameStr:'name' },
			{ label: '岗位',		name: 'project_id',				type: 'select', loading:true },
			{ label: '检测项目',		name: 'kind_id', 				type: 'select', loading:true },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		this.resetModel = { status: 'st_type_3' }
		this.model = $fn.copy(this.resetModel)
		if(window.isInit){
			this.fetch()
		}
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow( forms, 'project_parent_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 检测项目
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'project_name' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/labTATCount',{isIndex:true})
	
	// 表单
	cols = [
		{ title: '科室', 			dataIndex: 'project_parent_name', 	width:150 },
		{ title: '岗位', 			dataIndex: 'project_name', 			width:150 },
		{ title: '检测项目名称', 	dataIndex: 'single_kind_name', 		width:200 },
		{ title: '检测数量', 		dataIndex: 'count_total', 			width:100 },
		{ title: '50中位数', 		dataIndex: 'median_minute_50', 		width:100 },
		{ title: '90中位数', 		dataIndex: 'median_minute_90', 		width:100 },
		{ title: '最短报告时间', 	dataIndex: 'min_minute', 			width:100 },
		{ title: '最长报告时间', 	dataIndex: 'max_minute', 			width:100 },
	]
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this, 'statistics/labTATCount'),			// 导出
		]
	}
	
	render(){
		return (
			<>
				<Page title='TAT统计' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this,{isIndex:true, isInit:window.isInit}) }
				</Page>
			</>
		)
	}
}

export default Index